package io.zcoder.innoway.activities;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.zcoder.innoway.R;
import io.zcoder.innoway.utils.Utils;
import io.zcoder.innoway.commons.Constants;

public class WebViewActivity extends BaseActivity {

    @BindView(R.id.webview)
    WebView mWebView;
    String mUrl;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_webview_activity);
        ButterKnife.bind(this);
        showBack(true);

        mUrl = getIntent().getStringExtra(Constants.URL_EXTRAS);
        if (!Utils.isBlank(mUrl)) {
            if (mUrl.contains(Constants.URL_POLICY)) {
                setTitle(getString(R.string.privacy_policy));
            } else if (mUrl.contains(Constants.URL_TERM)) {
                setTitle(getString(R.string.terms_of_use));
            } else if (mUrl.contains(Constants.URL_FAQ)) {
                setTitle(getString(R.string.faq));
            }
            showProgress();
            mWebView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    hideProgress();
                    super.onPageFinished(view, url);
                }

                @Override
                public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
                    hideProgress();
                    super.onReceivedError(view, request, error);
                }
            });
            mWebView.loadUrl(mUrl);
        }

    }
}
